home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / libcruft / ranlib / gennch.f < prev    next >
Text File  |  1996-07-19  |  2KB  |  57 lines

  1.       REAL FUNCTION gennch(df,xnonc)
  2. C**********************************************************************
  3. C
  4. C     REAL FUNCTION GENNCH( DF, XNONC )
  5. C           Generate random value of Noncentral CHIsquare variable
  6. C
  7. C
  8. C                              Function
  9. C
  10. C
  11.  
  12. C     Generates random deviate  from the  distribution  of a  noncentral
  13. C     chisquare with DF degrees  of freedom and noncentrality  parameter
  14. C     XNONC.
  15. C
  16. C
  17. C                              Arguments
  18. C
  19. C
  20. C     DF --> Degrees of freedom of the chisquare
  21. C            (Must be > 1.0)
  22. C                         REAL DF
  23. C
  24. C     XNONC --> Noncentrality parameter of the chisquare
  25. C               (Must be >= 0.0)
  26. C                         REAL XNONC
  27. C
  28. C
  29. C                              Method
  30. C
  31. C
  32. C     Uses fact that  noncentral chisquare  is  the  sum of a  chisquare
  33. C     deviate with DF-1  degrees of freedom plus the  square of a normal
  34. C     deviate with mean XNONC and standard deviation 1.
  35. C
  36. C**********************************************************************
  37. C     .. Scalar Arguments ..
  38.       REAL df,xnonc
  39. C     ..
  40. C     .. External Functions ..
  41.       REAL genchi,gennor
  42.       EXTERNAL genchi,gennor
  43. C     ..
  44. C     .. Intrinsic Functions ..
  45.       INTRINSIC sqrt
  46. C     ..
  47. C     .. Executable Statements ..
  48.       IF (.NOT. (df.LE.1.0.OR.xnonc.LT.0.0)) GO TO 10
  49.       WRITE (*,*) 'DF <= 1 or XNONC < 0 in GENNCH - ABORT'
  50.       WRITE (*,*) 'Value of DF: ',df,' Value of XNONC',xnonc
  51.       CALL XSTOPX ('DF <= 1 or XNONC < 0 in GENNCH - ABORT')
  52.  
  53.    10 gennch = genchi(df-1.0) + gennor(sqrt(xnonc),1.0)**2
  54.       RETURN
  55.  
  56.       END
  57.